# Maintainer: Marcin Sielski <marcin.sielski@motorolasolutions.com>

_realname=rabbitmq-c
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.13.0
pkgrel=1
pkgdesc="RabbitMQ C client (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/alanxz/rabbitmq-c'
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-popt"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread-git")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/alanxz/${_realname}/archive/v${pkgver}.tar.gz"
        "0001-librabbitmq-CMakeLists.txt.patch")
sha256sums=('8b224e41bba504fc52b02f918d8df7e4bf5359d493cbbff36c06078655c676e6'
            'c82b9964e4e569303ca4369e632e7bec7c3c0d75992c5ffb2555700aba46d472')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-librabbitmq-CMakeLists.txt.patch
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G'Ninja' \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_SHARED_LIBRARY_NAME_WITH_VERSION=ON \
      "${extra_config[@]}" \
      -DBUILD_{SHARED,STATIC}_LIBS=ON \
      -DBUILD_TOOLS=ON \
      -DBUILD_TESTING=OFF \
      ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .
}
